/**
 * Created by tech6 on 2016/7/28.
 */

/**
 *
 * @param obj
 */
var consoleOpenWindowObj = function(obj) {
    art.dialog({
        id: "id-dialog-"+obj.id,
        title: obj.title,
        padding: 0,
        fixed: true,
        content: '<iframe height="'+(obj.height)+'px" width="'+(obj.width)+'px" frameborder=0 src="'+obj.url+'";></iframe>'
    });
}

/**
 *
 * @param id
 * @param url
 * @param title
 */
var consoleOpenWindow = function(id,url,title) {
    var height=$(window).height();
    var width=$(window).width();
    art.dialog({
        id: "id-dialog-"+id,
        title: title,
        padding: 0,
        fixed: true,
        content: '<iframe height="'+(height*0.8)+'px" width="'+(width*0.8)+'px" frameborder=0 src="'+url+'";></iframe>'
    });
}
/**
 *
 * @param id
 * @param url
 * @param title
 */
var consoleOpenHtmlWindow = function(id,html,title) {
    var height=$(window).height();
    var width=$(window).width();
    art.dialog({
        id: "id-dialog-"+id,
        title: title,
        padding: 0,
        fixed: true,
        content: html
    });
}
var consoleGrid=function(options){
    var obj = options ||{};
    this.table_id=obj.table_id;
    var self=this;
    this.update=function(id,url,message){
        var ids=[];
        $($("#"+self.table_id+"").bootstrapTable('getSelections')).each(function(i,o){
            ids.push( eval("o."+id+""));
        });
        if(ids.length==0){
            $.alert({
                title: '提示!',
                content: '请选择数据'
            });
        }else{
            $.confirm({
                title: '提示',
                content: message+'？',
                autoClose: 'cancelAction|3000',
                escapeKey: 'cancelAction',
                buttons: {
                    cancelAction: {
                        text: '取消',
                        action: function () {
                        }
                    }, ok: {
                        text: '确定',
                         action: function () {
                        $.post(url,{ids:ids.join(",")},function(data){
                            $("#"+self.table_id+"").bootstrapTable("refresh");
                        });
                }
                }
                }
            });
        }
    },
    this.delete=function(id,url){
        var ids=[];
        $($("#"+self.table_id+"").bootstrapTable('getSelections')).each(function(i,o){
            ids.push( eval("o."+id+""));
        });
        if(ids.length==0){
            $.alert({
                title: '提示!',
                content: '请选择数据'
            });
        }else{
            $.confirm({
                title: '提示',
                content: '是否删除？',
                autoClose: 'cancelAction|3000',
                escapeKey: 'cancelAction',
                buttons: {
                    cancelAction: {
                        text: '取消',
                        action: function () {
                        }
                    }, ok: {
                        text: '确定',
                        action: function () {
                            $.post(url,{ids:ids.join(",")},function(data){
                                $.alert({
                                    title: '提示!',
                                    content: data.message
                                });
                                $("#"+self.table_id+"").bootstrapTable("refresh");
                            });
                        }
                    }
                }
            });
        }
    },this.enterToQuery= function(event){
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e.keyCode == 13) {
                $('#'+self.table_id+'QuerySearch').click();
            }
    },
    this.init = function(){
        $('#'+self.table_id+'Reset').click(function() {
            $('#'+self.table_id+'_form').find('input,select').val('');
            $('#'+self.table_id+'_form').find('input[type="checkbox"]').attr('checked',false);
        });
        /**
         * 给搜索按钮绑定事件
         */
        $('#'+self.table_id+'QuerySearch').click(function() {
            $("#"+self.table_id+"").bootstrapTable("refresh");
        });
    }
};


function consoleTableDateFormat(timeStemp){
    if(timeStemp){
        return new Date(parseInt(timeStemp)).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
    }else{
        return "";
    }

}